<template>
  <div class="body-login">
    <el-form :model="loginForm" class="login-container" label-width="0px">
      <h3>欢迎登录</h3>
      <el-form-item prop="username">
        <el-input v-model="loginForm.username" placeholder="请输入用户名"></el-input>
      </el-form-item>
      <el-form-item  prop="password">
        <el-input v-model="loginForm.password" placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleLogin">登录</el-button>
      </el-form-item>
    </el-form> 
  </div>
</template>

<script setup>
import { reactive } from 'vue'
import { login } from '@/api/login'
import { useRouter } from 'vue-router'
import { useAllDateStore } from '@/stores'
const store = useAllDateStore()
const loginForm = reactive({
  username:'',
  password:'',
})
const router = useRouter() 
const handleLogin = ()=>{
  login(loginForm).then(res=>{
    console.log(res)
    store.updateToken(res.token)
    store.updateMenuList(res.menuList)
    router.push('/home')
    store.addDynamicRouter(router)
  })
}
</script>

<style scoped lang="less">
.body-login{
  height:100%;
  width: 100%;
  background: url('../assets/images/login-bg.jpeg') no-repeat center center;
  background-size: cover;
  overflow: hidden;
}
.login-container{
  width: 350px;
  margin: 150px auto;
  padding: 35px 35px 15px 35px;
  background: #fff;
  border-radius: 5px;
  box-shadow: 0 0 25px #cac6c6;
  h3{
    margin: 0px auto 20px auto;
    text-align: center;
    color: #505458;
  }
  :deep(el-from-item){
    margin-bottom: 20px;
  }
  :deep(.el-form-item__content){
    display: flex;
    justify-content: center;
  }
}
</style>